package net.itheima.mm.controller;

import lombok.extern.slf4j.Slf4j;
import net.itheima.mm.entity.PageResult;
import net.itheima.mm.entity.QueryPageBean;
import net.itheima.mm.entity.Result;
import net.itheima.mm.pojo.Course;
import net.itheima.mm.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @RequestMapping("/findListByPage")
    public Result findListByPage(@RequestBody QueryPageBean queryPageBean) {
        queryPageBean.setOffset(queryPageBean.getOffset());
        List<Course> courseList = courseService.findListByPage(queryPageBean);
        Long total = courseService.findTotalListByPage(queryPageBean);
        PageResult pageResult = new PageResult(total, courseList);
        log.info("[courselist数据:]data{}", courseList);
        return new Result(true, "获取学科列表成功", pageResult);
    }
}
